<html>
<head>
    <title>添加收费项目--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
    </style>
</head>
<body>
<form action="charge.html" id="myForm" method="post" class="definewidth m20">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="10%" class="tableleft">病例号</td>
            <td>
                <input type="text" readonly="readonly" id="id" name="id">
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">姓名</td>
            <td><input type="text" disabled=disabled id="registerName" name="registerName" /></td>
        </tr>

        <tr>

            <td width="10%" class="tableleft">添加项目</td>
            <td id="charges">

            </td>
        </tr>
        <tr>
            <td colspan="2">
                <center>
                    <button type="button" class="btn btn-primary" onclick="update()">保存</button> &nbsp;&nbsp;
                    <button type="button" class="btn btn-success" onclick="black()">返回列表</button>
                </center>
            </td>
        </tr>
    </table>
</form>
<script type="text/javascript">

    $(function () {
        showRegister();
        showCharge();
    })

    function black(){
        window.location.href="charge2.html";
    }

    //获取url
    (function($){
        $.getUrlParam
            = function(name)
        {
            var reg
                = new RegExp("(^|&)"+
                name +"=([^&]*)(&|$)");
            var r
                = window.location.search.substr(1).match(reg);
            if (r!=null) return unescape(r[2]); return null;
        }
    })(jQuery);
    var id = $.getUrlParam('id');

    //显示(Register)
    function showRegister() {
        $.ajax({
            url:"/checkCharge/getByidRegister?id="+id,
            type:"GET",
            success:function(register){
                var obj=register.obj;
                $("#id").val(obj.id);
                $("#registerName").val(obj.registerName);
            }
        })
    }
    //显示(Charge)
    function showCharge() {
        $.ajax({
            url:"/charge/getChargeNoDel",
            type:"GET",
            success:function(ov){
                let list=ov.list;
                let str="";
                for(let i=0;i<list.length;i++){
                    let obj=list[i];
                    let id=obj.id;
                    let chargeName=obj.chargeName;
                    str +=  '<input name="charge" type="checkbox" value= "'+ id + '">' +chargeName+'&nbsp;&nbsp;';
                }
                $("#charges").html(str);
            }
        })
    }

    function update() {
        var charge=[];
        $("input[name='charge']:checked").each(function(i){
            charge[i] = $(this).val();
        });
        if(charge.length<=0){
            alert("没有选择项目");
            return false;
        }
        $.ajax({
            url:"/checkCharge/addCharge",
            type:"POST",
            data: $("#myForm").serialize(),
            dataType:"json",
            success:function(ov){
                alert(ov.msg);
                if (ov.code==200){
                    black();
                }
            }
        })
    }

</script>
</body>
</html>
<script>

</script>